<%@ page language="java" pageEncoding="us-ascii" contentType="text/html;charset=us-ascii" %>
<%--Copyright (C) 2011 Wolfgang Hankeln, Norma J. Wendel
	 
	This file is part of CDinFusion.
	
	CDinFusion is free software: you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public 
	License in version 3 (LGPL3) as published by the Free Software
	Foundation version 3 of the License.
	
	CDinFusion is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	Lesser General Public License for more details.
	
	You should have received a copy of the Lesser General Public
	License along with CDinFusion; see the file COPYING. If not,
	write to the Free Software Foundation, 59 Temple Place - Suite 330,
	Boston, MA 02111-1307, USA or see <http://www.gnu.org/licenses/>.
	
	If you have any questions, send an email to: megx@mpi-bremen.de.
--%>
<%@ page import="org.cdinfusion.data.*"%>
<%@ page import="org.cdinfusion.data.studytype.*"%>
<%@ page import="org.cdinfusion.data.environment.*"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%System.out.println("<<<<<<<<<<4_MAPPING>>>>>>>>>>");%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<style type="text/css">
</style>
<title>MAPPING</title>
<jsp:include page="googleanalytics.jsp"/>

<script type="text/javascript"> 
function select(){
var itera = document.Formular.itera.value;
//alert("i: "+itera);
for(var j = 0; j < itera; j++){
	var studyselectmenu = document.getElementById('StudyTypeDropDown'+j);
	var envselectmenu = document.getElementById('EnvParamDropDown'+j);
	if(studyselectmenu.value == "none"){
		alert("Study type is none!");
		studyselectmenu.focus();
		return false;
	}
	if(envselectmenu.value == "none"){
		alert("Env type is none!");
		envselectmenu.focus();
		return false;
	}
}
return true;
}/*end function*/
</script>
</head>

<body>
<table border="0" width="100%" bgcolor="#2B3990" cellpadding=0 cellspacing=0>
<tr bgcolor="#ffffff">
<td width=250>
<center>
<img height="81" width="250" alt="CDinFusion Logo" src="/CDinFusion/img/logo_small_dark.png">
</center>
</td>
</tr>

<tr align="left">    
<td>
<jsp:include page="documentation/navigation.jsp"></jsp:include>
</td>
</tr>

<tr bgcolor="#ffffff">
<td>
<div class="center_div">    
<br>
<center><b> Map contextual data entries to sequences</b> <br><br>
</center>

<%
String origin = (String) session.getAttribute("origin");
Object obj1 = null;
Object obj2 = null;
List<CDElement> cdeLIST = (List<CDElement>) session.getAttribute("cdeLIST");
CDElement cdelement = null;
String env = null;
String study = null;
List<String> allSequenceIDs = (List<String>) session.getAttribute("allSequenceIDs");

if (cdeLIST.size() > 1){
	session.setAttribute("opt_2b", "many");
}
if (cdeLIST.size() == 1){
	session.setAttribute("opt_2b", "one");
}

int seq_num = 10;
int num_of_seq = allSequenceIDs.size();

if(request.getSession().getId().equalsIgnoreCase(session.getId())){
	if(cdeLIST.size() == 1){
			cdelement = cdeLIST.get(0);
			obj1 = cdelement.getStudy().getClass();
			obj2 = cdelement.getEnv().getClass();
			if(cdelement.getNumberOfSequences() == 1){
				out.print("The sequence");
				%><strong><%
				out.print(" "+cdelement.getFirstSequenceID());
				%></strong><%
				if(origin.equals("5")){
					out.print(" was mapped with ");
				}else{
					out.print(" is mapped with ");
				}
			}else{
				%>
				The group contains <strong><%=cdeLIST.get(0).getNumberOfSequences()%></strong> sequence IDs, they start with the ID 
				<strong><%=cdeLIST.get(0).getFirstSequenceID()%></strong> and end with <strong><%=cdeLIST.get(0).getLastSequenceID()%></strong>
				<%
				if(origin.equals("5")){
					out.print(" and was mapped with ");
				}else{
					out.print(" and is mapped with ");
				}
			}
			
			if(!obj1.toString().substring(36).equals("None_Study")){  
				out.print("the type of report ");
				%><strong><%
					if(obj1.toString().substring(36).equals("MIMARKS_S")) out.print("MIMARKS survey");
					if(obj1.toString().substring(36).equals("MIMARKS_C")) out.print("MIMARKS culture");
					if(obj1.toString().substring(36).equals("EU")) out.print("MIGS eukaryotes");
					if(obj1.toString().substring(36).equals("BA")) out.print("MIGS bacteria and archaea");
					if(obj1.toString().substring(36).equals("PL")) out.print("MIGS plasmid");
					if(obj1.toString().substring(36).equals("VI")) out.print("MIGS virus");
					if(obj1.toString().substring(36).equals("ORG")) out.print("MIGS organelle");
					if(obj1.toString().substring(36).equals("ME")) out.print("MIMS metagenome");
				%></strong><%
				if(!obj2.toString().substring(38).equals("None_Env")){
					out.print(" and ");
				}
			}
			if(!obj2.toString().substring(38).equals("None_Env")){
				out.print("the environmental package ");
				%><strong><%
					if(obj2.toString().substring(38).equals("Water")) out.print("water");
					if(obj2.toString().substring(38).equals("Wastewater")) out.print("wastewater/sludge");
					if(obj2.toString().substring(38).equals("Soil")) out.print("soil");
					if(obj2.toString().substring(38).equals("Sediment")) out.print("sediment");
					if(obj2.toString().substring(38).equals("Plant_associated")) out.print("plant-associated");
					if(obj2.toString().substring(38).equals("Miscellaneous")) out.print("miscellaneous");
					if(obj2.toString().substring(38).equals("Biofilm")) out.print("biofilm");
					if(obj2.toString().substring(38).equals("Human_vaginal")) out.print("human-vaginal");
					if(obj2.toString().substring(38).equals("Human_skin")) out.print("human-skin");
					if(obj2.toString().substring(38).equals("Human_oral")) out.print("human-oral");
					if(obj2.toString().substring(38).equals("Human_gut")) out.print("human-gut");
					if(obj2.toString().substring(38).equals("Human_associated")) out.print("human-associated");
					if(obj2.toString().substring(38).equals("Host_associated")) out.print("host-associated");
					if(obj2.toString().substring(38).equals("Air")) out.print("air");
				%></strong><%		
			}
			out.print(".");
			%><br><br><%
	}
	if(cdeLIST.size() > 1){
		for(int i = 0; i < cdeLIST.size(); i++){
		    final CDElement cdElement = cdeLIST.get(i);
			study = cdElement.getStudy().getClass().toString().substring(36).toLowerCase();
			env = cdElement.getEnv().getClass().toString().substring(38).toLowerCase();
			if(cdElement.getNumberOfSequences() > 1){
				%>
				The group <%=i+1%> contains <strong><%=cdElement.getNumberOfSequences()%></strong> sequence IDs, they start with the ID 
				<strong><%=cdElement.getFirstSequenceID()%></strong> and end with <strong><%=cdElement.getLastSequenceID()%></strong>
				<%
			} else if(cdElement.getNumberOfSequences() == 1){
				%>
				The group <%=i+1%> contains the sequence ID	<strong><%=cdElement.getFirstSequenceID()%></strong>
				<%
			}
			if(origin.equals("5")){
				out.print(" and was mapped with ");
			}else{
				out.print(" and is mapped with ");
			}
			if(!study.equals("none")){  
				out.print("the type of report ");
				%><strong><%
					if(study.equals("mimarks_s")) out.print("MIMARKS survey");
					if(study.equals("mimarks_c")) out.print("MIMARKS culture");
					if(study.equals("eu")) out.print("MIGS eukaryotes");
					if(study.equals("ba")) out.print("MIGS bacteria and archaea");
					if(study.equals("pl")) out.print("MIGS plasmid");
					if(study.equals("vi")) out.print("MIGS virus");
					if(study.equals("orga")|study.equals("org")) out.print("MIGS organelle");
					if(study.equals("me")) out.print("MIMS metagenome");
				%></strong><%
				if(!cdeLIST.get(i).equals("none")){
					out.print(" and ");
				}
			}
			if(!env.equals("none")){
				out.print("the environmental package ");
				%><strong><%
					if(env.equals("water")) out.print("water");
					if(env.equals("wastewater")) out.print("wastewater/sludge");
					if(env.equals("soil")) out.print("soil");
					if(env.equals("sediment")) out.print("sediment");
					if(env.equals("plant_associated")) out.print("plant-associated");
					if(env.equals("miscellaneous")) out.print("miscellaneous");
					if(env.equals("biofilm")) out.print("biofilm");
					if(env.equals("human_vaginal")) out.print("human-vaginal");
					if(env.equals("human_skin")) out.print("human-skin");
					if(env.equals("human_oral")) out.print("human-oral");
					if(env.equals("human_gut")) out.print("human-gut");
					if(env.equals("human_associated")) out.print("human-associated");
					if(env.equals("host_associated")) out.print("host-associated");
					if(env.equals("air")) out.print("air");
				%></strong><%		
			}
			out.print(".");
			%><br><br><%
		}
	}//end if(num_of_seq > seq_num)
}//end if(request.getSession().getId().equalsIgnoreCase(session.getId()))
if(origin.equals("5")){
	%>
	<form name="Form" action="maybe_go_back.htm" method="post">
		<p>
			Do you want to continue without changes? <input class="submitbutton" type="submit" name="submit" value="proceed">
		</p>
	</form><%
}%>
<form name="Formular" action="maybe_go_back.htm" method="post" onsubmit="return select()">
<%
boolean new_map = false;
if(origin.equals("5")){
	%>
	<hr>
	<%
	new_map = true;

	if(cdeLIST.size() == 1){
		%><input type="hidden" name="itera" value="<%=cdeLIST.size()%>"><%
			cdelement = cdeLIST.get(0);
			study = cdelement.getStudy().getClass().toString().substring(36).toLowerCase();
			env = cdelement.getEnv().getClass().toString().substring(38).toLowerCase();
			if(cdelement.getNumberOfSequences() == 1){%>
				<strong><%=cdeLIST.get(0).getFirstSequenceID()%></strong><%
	  		}else{%>
	  			<strong>Group 1</strong><%
	  		}%>
	  			<p style="margin-left: 220"> Type of report: <select name="StudyTypeDropDown<%=0%>" id="StudyTypeDropDown<%=0%>" size="1">
	  						<option value="none">none selected</option>
	  				<%
	  					if(study.equals("mimarks_s")){%> 
		      				<option value="mimarks_s <%=0%>">MIMARKS survey (mimarks_s) [1. group]</option>
		      			<%}
	      				if(study.equals("mimarks_c")){%>
		      				<option value="mimarks_c <%=0%>">MIMARKS culture (mimarks_c)  [1. group]</option>
		      			<%}
		      			if(study.equals("eu")){%>
		      				<option value="eu <%=0%>">MIGS eukaryotes (eu) [1. group]</option>
		      			<%}
		      			if(study.equals("ba")){%>
		      				<option value="ba <%=0%>">MIGS bacteria and archaea (ba) [1. group]</option>  
		      			<%}
		      			if(study.equals("pl")){%>
		      				<option value="pl <%=0%>">MIGS plasmid (pl) [1. group]</option>
		     			<%}
		      			if(study.equals("vi")){%>
		     				<option value="vi <%=0%>">MIGS virus (vi) [1. group]</option>
		      			<%}
		      			if(study.equals("orga")|study.equals("org")){%>
		      				<option value="orga <%=0%>">MIGS organelle (org) [1. group]</option>
		      			<%}
		      			if(study.equals("me")){%>
		      				<option value="me <%=0%>">MIMS metagenome (me) [1. group]</option>
		      			<%}%>
	  				</select>
	  			</p>
	  			<p style="margin-left: 220"> Environmental package: <select name="EnvParamDropDown<%=0%>" id="EnvParamDropDown<%=0%>" size="1">
	  						<option value="none">none selected</option>
	  				<%
		      			if(env.equals("water")){%>
		      				<option value="water <%=0%>">water [1. group]</option>
		      			<%}
		      			if(env.equals("wastewater")){%>
		      				<option value="wastewater <%=0%>">wastewater/sludge [1. group]</option>
		      			<%}
		      			if(env.equals("soil")){%>
		      				<option value="soil <%=0%>">soil [1. group]</option>
		      			<%}
		      			if(env.equals("sediment")){%>
		      				<option value="sediment <%=0%>">sediment [1. group]</option>
		      			<%}
		      			if(env.equals("plant_associated")){%>
		      				<option value="plant_associated <%=0%>">plant-associated [1. group]</option>
		      			<%}
		      			if(env.equals("miscellaneous")){%>
		      				<option value="miscellaneous <%=0%>">miscellaneous [1. group]</option>
		      			<%}
		      			if(env.equals("biofilm")){%>
		      				<option value="biofilm <%=0%>">microbial mat/biofilm [1. group]</option>
		      			<%}
		      			if(env.equals("human_vaginal")){%>
		      				<option value="human_vaginal <%=0%>">human-vaginal [1. group]</option>
		      			<%}
		      			if(env.equals("human_skin")){%>
		      				<option value="human_skin <%=0%>">human-skin [1. group]</option>
		      			<%}
		      			if(env.equals("human_oral")){%>
		      				<option value="human_oral <%=0%>">human-oral [1. group]</option>
		      			<%}
		      			if(env.equals("human_gut")){%>
		      				<option value="human_gut <%=0%>">human-gut [1. group]</option>
		      			<%}
		      			if(env.equals("human_associated")){%>
		      				<option value="human_associated <%=0%>">human-associated [1. group]</option>
		      			<%}
		      			if(env.equals("host_associated")){%>
		      				<option value="host_associated <%=0%>">host-associated [1. group]</option>
		      			<%}
		      			if(env.equals("air")){%>
		      				<option value="air <%=0%>">air [1. group]</option>
		      			<%}%>
	  				</select>
	  			</p>
      			<table>
      				<tr>
				    <td>Would you like to get a new FASTA header?
				    </td> 
				    <td><p style="margin-left: 100"></p> <select name="KeepFASTAHeader<%=0%>" size="1"> 
	      				<option value="false">yes</option>
	      				<option value="true">no</option>
					</select></td>
      				</tr>
      			</table>
	      		<%
	}//end if(cdeLIST.size() == 1)
		
	if(cdeLIST.size() > 1){
		%><input type="hidden" name="i" value="<%=cdeLIST.size()%>"><%
		for(int i = 0; i < cdeLIST.size(); i++){
			study = cdeLIST.get(i).getStudy().getClass().toString().substring(36).toLowerCase();
			env = cdeLIST.get(i).getEnv().getClass().toString().substring(38).toLowerCase();
			%><strong>Group <%=i+1%></strong>
	  			<p style="margin-left: 220"> Type of report: <select name="StudyTypeDropDown<%=i%>" id="StudyTypeDropDown<%=i%>" size="1">
	  				<option value="none">none selected</option>
	  				<%for(int j = 0; j < cdeLIST.size(); j++){
	  					if(study.equals("mimarks_s")){%> 
		      				<option value="mimarks_s <%=j%>">MIMARKS survey (mimarks_s) [<%=j+1%>. group]</option>
		      			<%}
	      				if(study.equals("mimarks_c")){%>
		      				<option value="mimarks_c <%=j%>">MIMARKS culture (mimarks_c)  [<%=j+1%>. group]</option>
		      			<%}
		      			if(study.equals("eu")){%>
		      				<option value="eu <%=j%>">MIGS eukaryotes (eu) [<%=j+1%>. group]</option>
		      			<%}
		      			if(study.equals("ba")){%>
		      				<option value="ba <%=j%>">MIGS bacteria and archaea (ba) [<%=j+1%>. group]</option>  
		      			<%}
		      			if(study.equals("pl")){%>
		      				<option value="pl <%=j%>">MIGS plasmid (pl) [<%=j+1%>. group]</option>
		     			<%}
		      			if(study.equals("vi")){%>
		     				<option value="vi <%=j%>">MIGS virus (vi) [<%=j+1%>. group]</option>
		      			<%}
		      			if(study.equals("orga")|study.equals("org")){%>
		      				<option value="orga <%=j%>">MIGS organelle (org) [<%=j+1%>. group]</option>
		      			<%}
		      			if(study.equals("me")){%>
		      				<option value="me <%=j%>">MIMS metagenome (me) [<%=j+1%>. group]</option>
		      			<%}
		      		}%>
	  				</select>
	  			</p>
	  			<p style="margin-left: 220"> Environmental package: <select name="EnvParamDropDown<%=i%>" id="EnvParamDropDown<%=i%>" size="1">
	  				<option value="none">none selected</option>
	  				<%for(int j = 0; j < cdeLIST.size(); j++){
		      			if(env.equals("water")){%>
		      				<option value="water <%=j%>">water [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("wastewater")){%>
		      				<option value="wastewater <%=j%>">wastewater/sludge [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("soil")){%>
		      				<option value="soil <%=j%>">soil [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("sediment")){%>
		      				<option value="sediment <%=j%>">sediment [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("plant_associated")){%>
		      				<option value="plant_associated <%=j%>">plant-associated [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("miscellaneous")){%>
		      				<option value="miscellaneous <%=j%>">miscellaneous [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("biofilm")){%>
		      				<option value="biofilm <%=j%>">microbial mat/biofilm [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("human_vaginal")){%>
		      				<option value="human_vaginal <%=j%>">human-vaginal [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("human_skin")){%>
		      				<option value="human_skin <%=j%>">human-skin [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("human_oral")){%>
		      				<option value="human_oral <%=j%>">human-oral [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("human_gut")){%>
		      				<option value="human_gut <%=j%>">human-gut [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("human_associated")){%>
		      				<option value="human_associated <%=j%>">human-associated [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("host_associated")){%>
		      				<option value="host_associated <%=j%>">host-associated [<%=j+1%>. group]</option>
		      			<%}
		      			if(env.equals("air")){%>
		      				<option value="air <%=j%>">air [<%=j+1%>. group]</option>
		      			<%}
		      		}%>
	  				</select>
	  			</p>
      			<table>
      				<tr>
				    <td>Would you like to get a new FASTA header?
				    </td> 
				    <td><p style="margin-left: 100"></p> <select name="KeepFASTAHeader<%=i%>" size="1"> 
	      				<option value="false">yes</option>
	      				<option value="true">no</option>
					</select></td>
      				</tr>
      			</table>
	      		<%
		}	
	}//end if(cdeLIST.size() > 1)
	session.setAttribute("origin", "4_again");
	%>
	<center><input class="submitbutton" type="submit" name="submit" value="change"></center>
<%}else{
	session.setAttribute("origin", "4");
	%>
	<center><input class="submitbutton" type="submit" name="submit" value="proceed"></center>
<%}%>
</form>
</div>
</td>
</tr>
<tr bgcolor="#ffffff"><td align="right" height=30>
	<img height="20" width="200" alt="CDinFusion Step 4" src="/CDinFusion/img/step4.png">
</td></tr>
<jsp:include page="documentation/bottom_info.jsp"></jsp:include>
</table>
</body>
</html>